package com.amex.uam.dao.impl;

import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.amex.uam.dao.ProjDao;
import com.amex.uam.model.MS_PROJ;
import com.amex.uam.model.MS_USER_PROJ;

@Repository("projDao")
public class ProjDaoImpl extends JdbcDao implements ProjDao {

	@Override
	public List<MS_PROJ> loadAllProjects() {
		final String SQL = "SELECT MS_PROJ_ID ,MS_PROJ_NM ,CREAT_TS FROM MS_PROJ";
		return this.getJdbcTemplate().query(SQL, ParameterizedBeanPropertyRowMapper.newInstance(MS_PROJ.class));
	}
	
	@Override
	public List<MS_USER_PROJ> getUserProjByUserID(String userId) {
		final String SQL = "SELECT distinct	C.MS_PROJ_ID, C.MS_PROJ_NM FROM	MS_USER_ADMIN A, MS_USER_PROJ B, MS_PROJ C WHERE A.WORKFORCE_MBR_ID=B.WORKFORCE_MBR_ID AND B.MS_PROJ_ID=C.MS_PROJ_ID AND A.USER_ID=?";
		Object[] params = {userId};
		return this.getJdbcTemplate().query(SQL, params, ParameterizedBeanPropertyRowMapper.newInstance(MS_USER_PROJ.class));
	}
	
	@Override
	public List<MS_USER_PROJ> getUserProjByMemberID(String amexWebId) {
		final String SQL = "SELECT	 distinct C.MS_PROJ_ID, C.MS_PROJ_NM FROM	MS_USER_ADMIN A, MS_USER_PROJ B, MS_PROJ C WHERE A.WORKFORCE_MBR_ID=B.WORKFORCE_MBR_ID AND B.MS_PROJ_ID=C.MS_PROJ_ID AND A.WORKFORCE_MBR_ID=?";
		Object[] params = {amexWebId};
		return this.getJdbcTemplate().query(SQL, params, ParameterizedBeanPropertyRowMapper.newInstance(MS_USER_PROJ.class));
	}
	
}
